<template>
  <div class="exhibition-box">
    <div class="exhibition" v-for="e in exhibition" :key="e.id">
      <div class="test">
        <img class="url" :src="e.cover_url" />
        <div class="mask"></div>
        <img class="arrow" @click="goback" src="@/assets/arrow/XO.png" />
        <div class="text">{{ e.title }}</div>
        <div class="text-item">
          <img class="img" src="@/assets/goImages/W71.png" />
          <div class="number">{{ e.pic_count }}</div>
        </div>
      </div>
      <div class="host-title">热度榜</div>

      <div class="host-list">
        <div v-for="a in e.rank_items" :key="a.id">
          <div class="box-item" @click="$router.push('/feeds/' + a.id)">
            <div><img class="pic" :src="a.cover_url" /></div>
            <div class="content-item">
              <span class="title">{{ a.title }}</span>
              <span class="desc">{{ a.desc }}</span>
              <span class="address">{{ a.address }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="host-venue">热门场馆</div>
      <div class="host-venue-list-box">
        <div class="host-venue-list" v-for="v in e.hot_businesses" :key="v.id" @click="$router.push('/businesses/' + v.id)">
          <div class="host-venue-list-content">
            <div class="host-venue-list-name">{{ v.title }}</div>
            <img class="host-venue-list-arrow" src="@/assets/arrow/L0.png" />
          </div>
          <div class="host-venue-list-count">{{ v.desc }}</div>
          <div class="host-venue-list-item-box">
            <div class="host-venue-list-item" v-for="item in v.children" :key="item.id">
              <img class="host-venue-list-img" :src="item.cover_url" />
              <div class="host-venue-list-text">{{ item.title }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="slideshow-box">
      <div class="slideshow">晒图</div>
      <div class="slideshow-change">
        <div class="slideshow-recommend" @click="clickRecommend" :class="change == true ? 'slideshow-active' : ''">推荐</div>
        <div class="Vertical"></div>
        <div class="slideshow-new" @click="clickNew" :class="change == false ? 'slideshow-active' : ''">最新</div>
      </div>
    </div>

    <refresh-list :status="status" @on-load="onLoad" @on-refresh="onRefresh" :canFresh="true">
      <template #list>
        <div class="figure-box" v-show="change == true">
          <div class="figure" v-for="(f, index) in Slideshow" :key="index" @click="goDynamic(f.pics[0].gif_url, f.id)">
            <img class="figure-img" v-lazy="f.pics[0].gif_url ? f.pics[0].gif_url : f.pics[0].url" />
            <div class="figure-title">{{ f.title }}</div>
            <div class="figure-item-box">
              <img class="figure-icon" src="@/assets/goImages/dZ.png" />
              <div class="city-name">{{ f.business && f.business.city }}.{{ f.business && f.business.name }}</div>
            </div>
            <div class="avatar-box">
              <div class="avatar-all">
                <img class="avatar_thumbnail" :src="f.send_user.avatar_thumbnail" />
                <img v-if="f.send_user.account_icon_url" class="account_icon_url" :src="f.send_user.account_icon_url" />

                <div class="avatar_name">{{ f.send_user.name }}</div>
              </div>
              <div class="like-box">
                <div class="like-heart" @click.stop="changeHeart(f)">
                  <img v-if="f.heart" class="heart-icon" src="@/assets/goImages/1t.png" />
                  <img v-else class="heart-icon" src="@/assets/goImages/AJ.png" />
                </div>
                <span class="like_count">{{ f.like_count }}</span>
              </div>
            </div>
          </div>
        </div>

        <div class="figure-box" v-show="change == false">
          <div class="figure" v-for="(f, index) in newest" :key="index" @click="goDynamic(f.pics[0].gif_url, f.id)">
            <img class="figure-img" v-lazy="f.pics[0].gif_url ? f.pics[0].gif_url : f.pics[0].url" />
            <div class="figure-title">{{ f.title }}</div>
            <div class="figure-item-box">
              <img class="figure-icon" src="@/assets/goImages/dZ.png" />
              <div class="city-name">{{ f.business && f.business.city }}.{{ f.business && f.business.name }}</div>
            </div>
            <div class="avatar-box">
              <div class="avatar-all">
                <img class="avatar_thumbnail" :src="f.send_user.avatar_thumbnail" />
                <img class="account_icon_url" :src="f.send_user.account_icon_url" />

                <div class="avatar_name">{{ f.send_user.name }}</div>
              </div>
              <div class="like-box">
                <div class="like-heart" @click.stop="changeHeart(f)">
                  <img v-if="f.heart" class="heart-icon" src="@/assets/goImages/1t.png" />
                  <img v-else class="heart-icon" src="@/assets/goImages/AJ.png" />
                </div>

                <span class="like_count">{{ f.like_count }}</span>
              </div>
            </div>
          </div>
        </div>
      </template>
    </refresh-list>
  </div>
</template>
<script>
import axios from '@/utils/request'
import { changeRedheart } from '@/utils/fabulous/index'
import RefreshList from '@/components/activity/public-component/RefreshList.vue'

export default {
  components: {
    RefreshList
  },
  data() {
    return {
      exhibition: [],
      Slideshow: [],
      newest: [],
      // change: true
      change: true,
      status: {
        isLoading: false,
        finished: false,
        loading: false
      },
      page: 1
    }
  },
  created() {
    this.RequestExhibition()
    this.RequestSlideshow()
    this.RequestNew()
    this.sendRequest()
  },
  methods: {
    async RequestExhibition() {
      const res = await axios.get('/v2/scenes/6')
      this.exhibition.push(res)
    },
    async RequestSlideshow() {
      const slideshow = await axios.get(`/v2/scenes/1/posts?sort_by=hot&page=${this.page}&limit=10`)
      if (slideshow.length > 0) {
        this.page++
        this.Slideshow = [...this.Slideshow, ...slideshow]
        this.status.isLoading = false
        this.status.loading = false
      } else {
        this.status.finished = true
      }
    },
    // 下拉刷新
    async onRefresh() {
      ;(this.data = []), (this.text = []), (this.list = []), (this.tag = []), (this.page = 1), (this.banner = []), (this.figure = []), (this.page = 1)
      await this.sendRequest()
      this.status.isLoading = false
    },
    // 滚动加载更多
    async onLoad() {
      await this.RequestSlideshow()
      await this.RequestNew()
      this.status.loading = false
    },
    async sendRequest() {
      const Toast = this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '加载中...'
      })
      await this.RequestSlideshow()
      await this.RequestNew()

      Toast.clear()
    },
    async RequestNew() {
      const slideshow = await axios.get(`/v2/scenes/1/posts?sort_by=time&page=${this.page}&limit=10`)
      if (slideshow.length > 0) {
        this.page++
        this.newest = [...this.newest, ...slideshow]
        this.status.isLoading = false
        this.status.loading = false
      } else {
        this.status.finished = true
      }
    },
    clickRecommend() {
      this.change = true
      if (this.change == true) {
        return
      } else {
        this.RequestSlideshow()
      }
    },
    clickNew() {
      this.change = false
      if (this.change == false) {
        return
      } else {
        this.RequestNew()
      }
    },
    goback() {
      this.$router.go(-1)
    },

    changeHeart(f) {
      let thisSet = this.$set
      changeRedheart(f, thisSet)
    },
    goDynamic(pic, id) {
      if (pic) {
        this.$router.push('/video/' + id)
      } else {
        this.$router.push('/dynamic/' + id)
      }
    }
  }
}
</script>
<style lang="less" scoped>
.exhibition-box {
  ::-webkit-scrollbar {
    display: none;
  }

  .search-bar {
    padding: 10px 0;
    position: sticky;
    top: 0;
    left: 0;
    background-color: #d94648;
    line-height: 22px;
    display: flex;
    height: 46px;
    align-items: center;
    z-index: 999;

    .arrow {
      width: 24px;
      height: 24px;
      margin-left: 20px;
    }

    .title {
      font-size: 18px;
      color: #fff;
      padding-left: 25px;
    }
  }
  .exhibition {
    .test {
      position: relative;
      overflow: hidden;
      height: 200px;

      .url {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        display: block;
        z-index: -2;
      }

      .mask {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: black;
        opacity: 0.38;
        z-index: -1;
      }

      .arrow {
        width: 24px;
        height: 24px;
        margin-left: 20px;
        margin-top: 40px;
      }

      .text {
        margin-top: 40px;
        margin-left: 20px;

        color: white;
        font-size: 20px;
        font-weight: bold;
      }

      .text-item {
        margin-top: 10px;
        margin-left: 20px;

        display: flex;
        .img {
          width: 13px;
          height: 13px;
        }

        .number {
          margin-left: 3px;

          font-size: 12px;
          color: white;
        }
      }

      .tags {
        margin: 20px 0;

        padding: 0 10px;
        overflow: auto;
        white-space: nowrap;
        display: flex;

        .tag-item {
          margin-right: 5px;
          font-size: 14px;
          padding: 5px 15px;
          border-radius: 999px;
          font-weight: 500;
          color: white;
          background-color: #fff5;
        }
      }
    }

    .host-title {
      font-size: 20px;
      font-weight: bold;
      margin-left: 7px;
      margin-top: 30px;
    }
    .host-venue {
      font-size: 20px;
      font-weight: bold;
      margin-left: 7px;
      margin-top: 25px;
    }

    .host-list {
      height: 263px;
      display: flex;
      flex-direction: column;
      overflow: auto;
      flex-wrap: wrap;

      .box-item {
        display: flex;
        width: 230px;
        margin-top: 15px;
        margin-left: 7px;
        .pic {
          width: 70px;
          height: 70px;
          border-radius: 5px;
        }
        .content-item {
          display: flex;
          flex-direction: column;
          margin-left: 5px;
          justify-content: space-around;
          font-size: 12px;

          .title {
            font-size: 13px;
            max-width: 140px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          .desc {
            color: rgb(178, 178, 178);
            max-width: 140px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          .address {
            color: rgb(178, 178, 178);
            max-width: 140px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }
    }

    .host-venue-list-box {
      display: flex;
      overflow: auto;

      .host-venue-list {
        margin-top: 30px;
        margin-left: 15px;
        border-bottom: 1px solid #fef4f4;
        border-radius: 5px;
        height: 180px;

        .host-venue-list-content {
          display: flex;
          justify-content: space-between;
          align-items: center;

          .host-venue-list-name {
            font-weight: bold;
            font-size: 14px;
          }

          .host-venue-list-arrow {
            width: 14px;
            height: 14px;
          }
        }

        .host-venue-list-count {
          color: red;
          font-size: 13px;
          margin-top: 7px;
        }

        .host-venue-list-item-box {
          display: flex;
          margin-top: 3px;
          .host-venue-list-item {
            display: flex;
            flex-direction: column;
            width: 108px;
            .host-venue-list-img {
              margin-top: 5px;
              width: 100px;
              height: 75px;
              border-radius: 5px;
              display: flex;
            }

            .host-venue-list-text {
              margin-top: 5px;
              white-space: normal;
              font-size: 14px;
              max-width: 100px;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
  .figure-box {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    margin-top: 20px;

    .figure {
      width: 176px;
      margin-left: 9px;
      margin-bottom: 17px;

      .figure-img {
        display: block;
        width: 170px;
        height: 200px;
        border-radius: 5px;
      }

      .figure-title {
        margin-left: 5px;
        margin-top: 5px;
        font-weight: bold;
        font-size: 13px;
      }
      .figure-item-box {
        display: flex;
        margin-top: 5px;
        margin-left: 5px;

        .figure-icon {
          width: 14px;
          height: 14px;
        }
        .city-name {
          margin-left: 8px;
          font-size: 13px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          max-width: 130px;
        }
      }
      .avatar-box {
        margin-top: 5px;
        display: flex;
        justify-content: space-around;
        align-items: center;

        .avatar-all {
          display: flex;
          align-items: center;
          flex: 1;
          margin-left: 5px;
          position: relative;

          .account_icon_url {
            position: absolute;
            left: 14px;
            top: -2px;
            width: 10px;
            height: 10px;
          }

          .avatar_thumbnail {
            width: 20px;
            height: 20px;
          }

          .avatar_name {
            font-size: 12px;
            margin-left: 8px;
          }
        }

        .like-box {
          display: flex;
          .like-heart {
            width: 16px;
            height: 14px;
            margin-right: 5px;

            .heart-icon {
              width: 100%;
              height: 100%;
              display: block;
              margin-right: 5px;
            }
          }
          .like_count {
            font-size: 12px;
          }
        }
      }
    }
  }
  .slideshow-box {
    display: flex;
    justify-content: space-between;
    margin: 0 7px;
    margin-top: 35px;

    .slideshow {
      font-size: 20px;
      font-weight: bold;
    }

    .slideshow-change {
      display: flex;
      align-items: center;
      font-size: 14px;
      color: #a7a7a7;

      .slideshow-active {
        color: red;
      }

      .Vertical {
        width: 1px;
        height: 12px;
        margin: 0 5px;
        background-color: #a7a7a7;
        margin-top: -2px;
      }
    }
  }
}
</style>
